﻿@using Newtouch.OR.ManageSystem.Infrastructure
@{
	ViewBag.Title = "Index";
	Layout = "~/Views/Shared/_Index.cshtml";
}
<style>
	body {
		filter: drop-shadow(0 1em 1em rgba(0, 0, 0, 0.2));
		background: #fff;
	}

	p {
		/*box-sizing: border-box;
		display: flex;
		align-items:  center;
		justify-content: space-between;
		position: relative;*/
		margin: 1.0em auto;
		border: solid 0.5em transparent;
		padding: 0.2em;
		width: 15em;
		height: 2.8em;
		border-radius: 2.5em;
		background: Linear-gradient(#dbdbdb, #fff) content-box, Linear-gradient(var(--slist)) padding-box, Linear-gradient(#fff, #dcdcdc) border-box;
		font: bold 1.5em/ 1.375 trebuchet ms, verdana, sans-serif;
		text-align: center;
		text-indent: 1em;
		-webkit-clip-path: inset(0 round 2.5em);
		clip-path: inset(0 round 2.5em);
		counter-increment: c;
	}

</style>
<script src="@SiteUrl.GetStaticResourceScriptUrl("~/js/validate/jquery.validate.min.js")"></script>
<link href="~/Content/css/card.css" rel="stylesheet" />
<form id="formarrangement">
	<div class="panel">
		<div id="dv_apply" style="width:30%;float:left;">
			<p style="--slist: #90cbb7,#2fb1a9;">
				<span id="xm">张三</span><br />
				<span id="xb" style="font-size:13px;">男，26岁</span>
			</p>
			<table class="form">
				<tr>
					<th class="formTitle">住院号：</th>
					<td class="formValue" id="zyh">001</td>
					<th class="formTitle">病区：</th>
					<td class="formValue" id="bq" style="width: 90px;">一病区</td>
				</tr>
				<tr>
					<th class="formTitle">床号：</th>
					<td class="formValue" id="ch">C098</td>
				</tr>
				<tr>
					<th class="formTitle">入院诊断：</th>
					<td class="formValue" colspan="2" id="ryzd">阑尾炎</td>
				</tr>
			</table>
			<table class="form" style="font-size:13px;border-radius: 4px;box-shadow: 0 0 2px #808080 inset;padding: 5px 15px 5px 15px;font-weight:bold;">
				<tr>
					<td class="formValue"></td>
				</tr>
				<tr>
					<td class="formValue" colspan="2" style="border-bottom:solid;border-bottom-left-radius:5px;border-bottom-color:#90cbb7;">
						<span style="padding-left:10px;">手术申请详情</span>
					</td>
				</tr>
				<tr style="height:50px;">
					<th class="formTitle">申请手术名称：</th>
					<td class="formValue" id="ssmcn"></td>
				</tr>
				<tr style="height:50px;">
					<th class="formTitle">申请主刀医生：</th>
					<td class="formValue" id="ysxm"></td>
				</tr>
				<tr style="height:50px;">
					<th class="formTitle">申请手术时间：</th>
					<td class="formValue" id="sssj"></td>
				</tr>
				<tr style="height:50px;">
					<th class="formTitle">申请状态：</th>
					<td class="formValue" id="sqzt" data-enumtype="EnumSqzt">待审核</td>
				</tr>
			</table>
		</div>
		<div id="dv_arrange" style="width:70%;float:right;">
			<div class="panel-heading" style="border-bottom-color:#90cbb7;border-bottom-left-radius:20px;">
				<span class="glyphicon glyphicon-tags" style="color: rgb(255, 140, 60);"></span>
				<span style="font-weight:bold;font-size:14px;padding-left:10px;">手术安排</span>
			</div>
			<div id="dv_step1">
				<table class="form">
					<tr>
						<th class="formTitle"><span class="required">*</span>拟手术名称：</th>
						@*<td class="formValue formDdlSelectorTd" colspan="3">
			<input id="ssmc" type="text" readonly="readonly" class="form-control required" />
		</td>*@
						<td class="formValue" colspan="3">
							<table id="tablessmc">
								<tr>
									<td>
										<i id="zdCircle" class="fa fa-plus-circle plusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i>
									</td>

									<td class="formValue">
										<input type="text" class="form-control activeValue focusInput ssmcText" id="ssmc" name="ssmc" readonly="readonly"/>
										<input id="ssdm" type="hidden" />
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th class="formTitle "><span class="required">*</span>手术时间：</th>
						<td class="formValue" colspan="2">
							<input id="sssj2" type="text" class="form-control input-wdatepicker formClearIgnore required" style="width:70%;" value="" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm' })" />
						</td>
						<td class="formValue"></td>
					</tr>
					<tr>
						<th class="formTitle"><span class="required">*</span>麻醉方式：</th>
						<td class="formValue formDdlSelectorTd">
							<select id="mzfs" name="mzfs" class="form-control required" style="width:95%;float:left;">
								<option value="">===请选择=== </option>
								<option value="1"> 全身麻醉 </option>
								<option value="2">局部麻醉</option>
								<option value="3">针刺麻醉</option>
								<option value="4">复合麻醉</option>
							</select>
						</td>
						<th class="formTitle">手术部位：</th>
						<td class="formValue formDdlSelectorTd">
							<input id="ssbw" type="text" class="form-control" />
						</td>
						<td class="formValue"></td>
					</tr>
					<tr>
						<td class="formTitle"><span class="required">*</span>手术室：</td>
						<td class="formValue formDdlSelectorTd">
							<select id="oproom" name="oproom" class="form-control required">
								<option value=""> ==请选择== </option>
								@*<option value="2">手术室2</option>
									<option value="3">手术室3</option>*@
							</select>
						</td>
						<td class="formTitle">台次：</td>
						<td class="formValue">
							<input id="sstc" type="text" class="form-control" />
						</td>
					</tr>
					<tr>
						<th class="formTitle"><span class="required">*</span>是否隔离：</th>
						<td class="formValue formDdlSelectorTd">
							<select id="isgl" name="isgl" class="form-control required" style="width:95%;float:left;">
								<option value="2">否</option>
								<option value="1">是 </option>

							</select>
						</td>
					</tr>
				</table>

			</div>
			<div class="panel-heading" style="border-bottom-color:#90cbb7;border-bottom-left-radius:20px;">
				<span class="glyphicon glyphicon-tags" style="color: rgb(255, 140, 60);"></span>
				<span style="font-weight:bold;font-size:14px;padding-left:10px;">医护人员安排</span>
			</div>
			<div id="dv_step2">
				<table class="form">
					<tr>
						<th class="formTitle"><span class="required">*</span>主刀医生：</th>
						<td class="formValue formDdlSelectorTd required">
							<input id="code1" class="required" type="hidden" />
							<input id="ysgh" attr-code="" attr-zjm="" name="ysgh" type="text" class="form-control required" autocomplete="off" />

						</td>
						<th class="formTitle"></th>
						<td class="formValue"></td>
						<th class="formTitle"></th>
						<td class="formValue"></td>
					</tr>
					<tr>
						<th class="formTitle">一助：</th>
						<td class="formValue formDdlSelectorTd">
							<input id="zlys1" type="hidden" />
							<input id="zlys1name" attr-code="" attr-zjm="" name="zlys1name" type="text" class="form-control" autocomplete="off" />

						</td>
						<th class="formTitle">二助：</th>
						<td class="formValue formDdlSelectorTd">
							<input id="zlys2" type="hidden" />
							<input id="zlys2name" attr-code="" attr-zjm="" name="zlys2name" type="text" class="form-control" autocomplete="off" />
						</td>
					</tr>
					<tr>
						<th class="formTitle">巡回护士：</th>
						<td class="formValue formDdlSelectorTd">
							<input id="xhhs" type="hidden" />
							<input id="xhhsname" attr-code="" attr-zjm="" name="xhhsname" type="text" class="form-control" autocomplete="off" />
						</td>
						<th class="formTitle"></th>
						<td class="formValue"></td>
					</tr>
					<tr>
						<th class="formTitle">洗手护士：</th>
						<td class="formValue formDdlSelectorTd">
							<input id="xshs" type="hidden" />
							<input id="xshsname" attr-code="" attr-zjm="" name="xshsname" type="text" class="form-control" autocomplete="off" />
						</td>
						<th class="formTitle"></th>
						<td class="formValue"></td>
					</tr>
				</table>
			</div>
			<div class="panel-heading" style="border-bottom-color:#90cbb7;border-bottom-left-radius:20px;">
				<span class="glyphicon glyphicon-tags" style="color: rgb(255, 140, 60);"></span>
				<span style="font-weight:bold;font-size:14px;padding-left:10px;">请仔细核对以上手术安排</span>
			</div>
            <div style="padding-top:30px;width:300px;float:right;">
                <table>
                    <tr>
                        <td style="padding-right:10px;">
                            <a class='btn btn-default' id="cancel" style='width:80px;background:#c1958f;color:#eee;height:20px;font-size:13px;padding-top:5px;' onclick="cancelArrange();"><span class="glyphicon glyphicon-remove">取消排班</span></a>
                        </td>
                        <td style="padding-right:10px;">
                            <a class='btn btn-default' id="submit" style='width:80px;background:#00CD66;color:#eee;height:20px;font-size:13px;padding-top:5px;' onclick="submitArrange();"><span class="glyphicon glyphicon-ok">保存排班</span></a>
                        </td>
                        <td>
                            <a class='btn btn-default' id="print" style='width:80px;background:#2fb1a9;color:#eee;height:20px;font-size:13px;padding-top:5px;' onclick="printArrange();"><span class="glyphicon glyphicon-print">打印通知单</span></a>
                        </td>
                    </tr>
                </table>
            </div>
		</div>
	</div>
</form>
<script>
    var applyno = "";
	$(function () {
		getArrangeInfo();
		getApplyInfo();
		getSelectBind();
	});

	function getSelectBind() {
		$("#oproom").bindSelect({
			url: "/Operation/Common/GetRoomlist",
			id: "Code",
			text: "Name",
			minimumResultsForSearch: 0
		});
		$("#mzfs").bindSelect({
			url: "/Operation/Common/GetAneslist",
			id: "AnesCode",
			text: "AnesName"
		});
		//$("#ysgh").bindSelect({
		//	url: "/Operation/Common/GetStafflist",
		//	id: "rygh",
		//	text: "ryxm",
		//	minimumResultsForSearch: 0
		//});
		//$("#zlys1").bindSelect({
		//	url: "/Operation/Common/GetStafflist",
		//	id: "rygh",
		//	text: "ryxm"
		//});
		//$("#zlys2").bindSelect({
		//	url: "/Operation/Common/GetStafflist",
		//	id: "rygh",
		//	text: "ryxm"
		//});
		//$("#xhhs").bindSelect({
		//	url: "/Operation/Common/GetStafflist",
		//	id: "rygh",
		//	text: "ryxm"
		//});
		//$("#xshs").bindSelect({
		//	url: "/Operation/Common/GetStafflist",
		//	id: "rygh",
		//	text: "ryxm"
		//});
		$("#ysgh").staffFloatingSelector({
			organizeId: '',
			width: 200,
			itemdbclickhandler: function ($this) {
				$("#ysgh").val($this.attr('data-name')).attr("attr-code", $this.attr('data-id')).attr("attr-zjm", $this.attr('data-zjm'));
				var name = $("#code1").val($this.attr('data-name')).val();
				var code = $("#code1").val($this.attr('data-code')).val();
				$("#ysgh").html(name);
				$("#code1").html(code);
			}
		});
		$("#zlys1name").staffFloatingSelector({
			organizeId: '',
			width: 200,
			itemdbclickhandler: function ($this) {
				$("#zlys1name").val($this.attr('data-name')).attr("attr-code", $this.attr('data-id')).attr("attr-zjm", $this.attr('data-zjm'));
				var name = $("#zlys1").val($this.attr('data-name')).val();
				var code = $("#zlys1").val($this.attr('data-code')).val();
				$("#zlys1name").html(name);
				$("#zlys1").html(code);
			}
		});
		$("#zlys2name").staffFloatingSelector({
			organizeId: '',
			width: 200,
			itemdbclickhandler: function ($this) {
				$("#zlys2name").val($this.attr('data-name')).attr("attr-code", $this.attr('data-id')).attr("attr-zjm", $this.attr('data-zjm'));
				var name = $("#zlys2").val($this.attr('data-name')).val();
				var code = $("#zlys2").val($this.attr('data-code')).val();
				$("#zlys2name").html(name);
				$("#zlys2").html(code);
			}
		});
		$("#xhhsname").staffFloatingSelector({
			organizeId: '',
			width: 200,
			itemdbclickhandler: function ($this) {
				$("#xhhsname").val($this.attr('data-name')).attr("attr-code", $this.attr('data-id')).attr("attr-zjm", $this.attr('data-zjm'));
				var name = $("#xhhs").val($this.attr('data-name')).val();
				var code = $("#xhhs").val($this.attr('data-code')).val();
				$("#xhhsname").html(name);
				$("#xhhs").html(code);
			}
		});
		$("#xshsname").staffFloatingSelector({
			organizeId: '',
			width: 200,
			itemdbclickhandler: function ($this) {
				$("#xshsname").val($this.attr('data-name')).attr("attr-code", $this.attr('data-id')).attr("attr-zjm", $this.attr('data-zjm'));
				var name = $("#xshs").val($this.attr('data-name')).val();
				var code = $("#xshs").val($this.attr('data-code')).val();
				$("#xshsname").html(name);
				$("#xshs").html(code);
			}
		});
	}


	//手术名称 新增icon
	$('#tablessmc .plusToggleCircle').click(function () {
		var number = $('#tablessmc .ssmcText').length + 1;
		//var $newTr = $('<tr><th class="formTitle">副7</th><td class="formValue"><input type="checkbox" id="chk' + number + '" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label><input type="text" id="zd' + number + '" class="form-control activeValue focusInput zdText" style="width:70%;" /><i class="fa fa-times" aria-hidden="true" hidden></i></td><td><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i></td></tr>');
		var $newTr = $('<tr><td><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i></td><td class="formValue"><input type="text" readonly="readonly" id="ssmc' + number + '" name="ssmc' + number + '" class="form-control activeValue focusInput ssmcText" /><input id="ssdm' + number + '" type="hidden" /></td></tr>');
		$newTr.appendTo($(this).closest('table'));
		//手术名称浮层
		//bindssmcFloatingSelector(number);
	});

	//删除icon
	$('#formarrangement').on('click', '.minusToggleCircle', function () {
		$(this).closest('tr').remove();
	});

	//主手术浮层
	//bindssmcFloatingSelector(0);
	

	var applyInfo = {};
	function getApplyInfo() {
		var keyValue = $.request("keyValue");
		var sqzt = $.request("sqzt");
		$.ajax({
			url: "/Operation/OpArrangement/GetApplyInfoByKey?keyValue=" + keyValue,
			data: { keyValue: "" },
			dataType: "json",
			success: function (data) {
				//手术申请信息
				arrangeInfo = data;
				var xb = data.xb == 1 ? "男" : "女";
				xb += data.nl == null ? "" : "，" + data.nl;
				$("#xm").html(data.xm);
				$("#xb").html(xb);
				$("#zyh").html(data.zyh);
				$("#bq").html(data.bq);
				$("#ch").html(data.ch);
				$("#ryzd").html(data.zd);
				$("#ssmcn").html(data.ssmcn);
				$("#ysxm").html(data.ysxm);
				$("#sssj").html(data.sssj.replace("T", " "));
                $("#sqzt").html(data.sqzt);

				applyno = data.Applyno;

				//手术名称
				var number = data.ss.length;
				if (number > 0) {//主手术
					$("#ssmc").val(data.ss[0].ssmc);
					$("#ssdm").val(data.ss[0].ssdm);
				}
				for (var i = 1; i < number; i++) {
					var n = i + 1;
					//if ($("#ssdm" + n).val() == "") {
					if ($("#ssdm" + n).length <= 0) {
						//添加icon 并赋值
						$('#tablessmc .plusToggleCircle').click();
						$("#ssmc" + n).val(data.ss[i].ssmc);
						$("#ssdm" + n).val(data.ss[i].ssdm);
					}
				}
			}
		});
	}

	var arrangeInfo = {};
	function getArrangeInfo() {
		var ApplyId = $.request("keyValue");
		//var sqzt = $.request("sqzt");
		$.ajax({
			url: "/Operation/OpArrangement/GetArrangeObjByApplyId?ApplyId=" + ApplyId,
			data: { ApplyId: "" },
			dataType: "json",
			success: function (data) {
				$("#formarrangement").formSerialize(data);
				//手术排班信息
				//$("#ssmc").val(data.ssmcn);
				if (data.sssj != null) {
					$("#sssj2").val(data.sssj.replace("T", " "));
				}
				$("#mzfs").val(data.AnesCode).trigger("change");
				$("#ysgh").val(data.ysxm);
				$("#ssbw").val(data.ssbw);
				//$("#roomlist").val(data.oproom);
				//$("#roomlist").get(0).value = data.oproom;
				//$("#roomlist").find("option[value ='C3']").attr("selected", true);
				$("#sstc").val(data.oporder);
				//$("#isgl").val(data);
				//$("#zdyslist").val(data.ysgh);
				//$("#sszl1").val(data.zlys1);
				//$("#sszl2").val(data.zlys2);
				//$("#ssxhhs").val(data.xhhs);
				//$("#ssxshs").val(data.xshs);
				//var ssxshs = $("#ssxshs option:selected").text();
				//$("#ssxshs").val(ssxshs);
				//$("#ssxhhs option[value='ys07']").attr("selected", "selected");
				//按钮显示隐藏
				if (data.sqzt == '@((int)EnumSSzt.dpb)') {
					$("#cancel").hide();
                    $("#submit").show();
                    $("#print").hide();
				} else if (data.sqzt == '@((int)EnumSSzt.ypb)') {
					$("#cancel").show();
                    $("#submit").show();
                    $("#print").show();	
				} else if (data.sqzt == '@((int)EnumSSzt.yzf)') {
					$("#cancel").hide();
                    $("#submit").hide();
                    $("#print").hide();
                } else if (data.sqzt == '@((int)EnumSSzt.yzx)')
                {
                    $("#cancel").hide();
                    $("#submit").hide();
                    $("#print").show();
                }
                else {
					$("#cancel").hide();
                    $("#submit").show();
                    $("#print").hide();
				}
			}
		});
	}

	//保存排班
	function submitArrange() {

		if (!$('#formarrangement').formValid()) {
			return false;
		}

		var arrangeObj = {
			ApplyId: arrangeInfo.Id,
			Applyno: arrangeInfo.Applyno,
			ssxh: arrangeInfo.ssdm,
			zyh: arrangeInfo.zyh,
			xm: arrangeInfo.xm,
			ks: arrangeInfo.ks,
			bq: arrangeInfo.bq,
			ch: arrangeInfo.ch,
			zd: arrangeInfo.zd,
			sqzt: 2,
			ssmc: arrangeInfo.ssmcn,
			ssdm: arrangeInfo.ssdm,
			//sssj: arrangeInfo.sssj,
			sssj: $("#sssj2").val(),
			ysgh: $("#code1").val() == "" ? arrangeInfo.ysgh : $("#code1").val(),
			ysxm: $("#ysgh").val(),
			AnesCode: $("#mzfs").val(),
			oproom: $("#oproom").val(),
			oporder: $("#sstc").val(),
			zlys1: $("#zlys1").val(),
			zlys2: $("#zlys2").val(),
			zlys3: null,
			zlys4: null,
			xhhs: $("#xhhs").val(),
			xshs: $("#xshs").val(),
			ssbw: $("#ssbw").val(),
			zt: 1,
		}
		if (arrangeObj.sssj == "") {
			$.modalAlert("请填写手术时间", 'warning');
		} else {
		//不可填
		$("#sssj2").attr("disabled", "disabled");
		$("#mzfs").attr("disabled", "disabled");
		$("#ssbw").attr("readonly", true);
		$("#oproom").attr("disabled", "disabled");
		$("#sstc").attr("readonly", true);;
		$("#isgl").attr("disabled", "disabled");
		$("#ysgh").attr("disabled", "disabled");
		$("#zlys1").attr("disabled", "disabled");
		$("#zlys2").attr("disabled", "disabled");
		$("#xhhs").attr("disabled", "disabled");
		$("#xshs").attr("disabled", "disabled");
		var keyValue = $.request("keyValue");

		
		$.submitForm({
			url: "/Operation/OpArrangement/submitForm?keyValue=" + keyValue,
			param: arrangeObj,
			success: function () {
				//getApplyInfo();
                //getArrangeInfo();
                location.reload();
			}
			});

		}

	}

	//取消排班
	function cancelArrange() {
		window.$.modalConfirm("确定要取消吗？", function (flag) {
			if (!flag) {
				return false;
			}
			return true;
		});
		var keyValue = $.request("keyValue");
		if (!!!keyValue) {
			window.$.modalAlert("取消安排失败", 'warning');
			return false;
		}
		window.$.deleteForm({
			url: "/Operation/OpArrangement/DeleteForm",
			param: { keyValue: keyValue },
			success: function () {
				$.modalMsg("取消成功", "success");
				$("#gridList").trigger("reloadGrid");
			}
		});
		return true;
	}

	function showOPmaterial() {

    }

    function printArrange() {
        window.open("/ReportManage/Report/OperationNoticeReport?zyh=" + $("#zyh").val() + "&applyno=" + arrangeInfo.Applyno);
    }
</script>